// pages/appointment/appointment.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    addnoteBtnShow: false,
    appoList: []
  },
  // 关闭当前打开的备注弹框
  closeaddnoteBtnShow:function(){
    let that = this
    that.setData({
      addnoteBtnShow: !that.data.addnoteBtnShow
    })
  },
  // 防止触摸 
  stop: function() {
    return false
  },
  // 获取填写的备注信息
  haveNoteNews: function(e) {
    console.log(e)
    
    let that = this
    that.setData({
      baveNoteNews: e.detail.value
    })
    
  },
  addnoteOkBtn: function() {
    let that = this
    that.setData({
      addnoteBtnShow: !that.data.addnoteBtnShow
    })
    let newNote = that.data.baveNoteNews 
    let pid = that.data.pid
    console.log(wx.getStorageSync("userInfo"))
    if (newNote == "" || newNote==undefined){
      wx.showModal({
        title: '提示',
        content: '请重新填写备注信息',
      })
      return
    }

    var url = app.util.url('entry/wxapp/addbz')
    app.util.request({
      url: url,
      data: {
        m: 'md_daojia',
        uid: wx.getStorageSync("userInfo"),
        pid: pid,
        note: newNote
      },
      success: function(res) {
       
            let list = that.data.appoList
            let ind = that.data.ind
            list[ind].beizhu = newNote
            that.setData({
              appoList: list
            })
        
      }
    })
  },
  // 位当前预约人员添加备注信息
  addnoteBtn: function(e) {
    console.log(e.currentTarget.dataset.pid)
    let that = this
    that.setData({
      addnoteBtnShow: !that.data.addnoteBtnShow,
      pid: e.currentTarget.dataset.pid,
      ind: e.currentTarget.dataset.ind
    })

  },

  onLoad: function(options) {
    var _that = this
    _that.appoList()
  },


  //  跳转陪同记录
  btnRecord: function() {
    wx.navigateTo({
      url: '/pages/appointment/record',
    })
  },

  //  预约陪同请求接口
  appoList: function() {
    var that = this;
    var url = app.util.url('entry/wxapp/accompany')
    app.util.request({
      url: url,
      data: {
        m: 'md_daojia',
        uid: wx.getStorageSync("userInfo")
      },
      success: function(res) {
        var list = res.data.data
        list.map(function(item, index) {
          item.bind = 'btnDetail'
        })
        that.setData({
          appoList: list
        })
        console.log("预约陪同=========>", res);

      }
    })
  },

  // 预约
  btnDetail: function(t) {
    var index = t.currentTarget.dataset.index
    var appoList = this.data.appoList
    appoList.map(function(item, indexs) {
      index == indexs && wx.navigateTo({
        url: '/pages/appointment/details?pid=' + item.id + '&price=' + item.price,
      })
    })
    console.log("预约详情", index)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})